package tasks.OpportunitiesBaseData.Filters;
import resources.tasks.OpportunityViewFiltersHelper;
import com.rational.test.ft.*;
import com.rational.test.ft.object.interfaces.*;
import com.rational.test.ft.object.interfaces.SAP.*;
import com.rational.test.ft.object.interfaces.WPF.*;
import com.rational.test.ft.object.interfaces.dojo.*;
import com.rational.test.ft.object.interfaces.siebel.*;
import com.rational.test.ft.object.interfaces.flex.*;
import com.rational.test.ft.object.interfaces.generichtmlsubdomain.*;
import com.rational.test.ft.script.*;
import com.rational.test.ft.value.*;
import com.rational.test.ft.vp.*;
import com.ibm.rational.test.ft.object.interfaces.sapwebportal.*;

import core.Configurations;
import core.ControlsMapping;
import core.controls.SelectBox;
import core.enums.TimePeriod;
import core.exceptions.ResultFailureException;
import core.testcases.TestProjectSuperHelper;
/**
 * Description   : Functional Test Script
 * @author angel.tsvetkov
 */
public class Applier extends TestProjectSuperHelper
{
    private boolean applyFilter(String filterName, SelectBoxVal[] selectBoxes, boolean applyFilter)
    {
		boolean result = true;
		String taskReport = "";
		
		try
		{
			for(SelectBoxVal selectBox:selectBoxes)
			{
				if(selectBox.getValue() != null)
				{
					taskReport += "Choose " + selectBox.getValue() + " option in " + selectBox.getSelectBoxObj().getDescriptiveName();
					selectBox.getSelectBoxObj().select(selectBox.getValue());
				}
			}
			
			if(applyFilter)
			{
				taskReport += "\n Press " + ControlsMapping.FilterCommonElements.GO_button.getDescriptiveName();
				ControlsMapping.FilterCommonElements.GO_button.click();
			}
			
		}catch(ResultFailureException ex)
		{
			result = false;
			setErrorComment(ex.getError());
		}

		setTaskResult("Task: Configure " + filterName, result, taskReport);
		
		return result;
    }
    
    public boolean applyGeographyFilter(String iotVal, String imtVal, String gmrVal, String countryVal)
    {
    	return applyGeographyFilter(iotVal, imtVal, gmrVal, countryVal, true);
    }
    
    public boolean applyGeographyFilter(String iotVal, String imtVal, String gmrVal, String countryVal, boolean applyFilter)
    {
    	String filterName = "Geography Filter";
    	
    	SelectBoxVal[] selectBoxes = {new SelectBoxVal(iotVal, ControlsMapping.GeographyFilter.IOT_listbox),
    			new SelectBoxVal(imtVal, ControlsMapping.GeographyFilter.IMT_listbox),
    			new SelectBoxVal(gmrVal, ControlsMapping.GeographyFilter.GMR_listbox),
    			new SelectBoxVal(countryVal, ControlsMapping.GeographyFilter.Country_listbox)}; 
    	
		return applyFilter(filterName, selectBoxes, applyFilter);
    }
    
    public boolean applySellerFilter(String territoryType, String role, String sellerName)
    {
    	return applySellerFilter(territoryType, role, sellerName, true);
    }
    
    public boolean applySellerFilter(String territoryType, String role, String sellerName, boolean applyFilter)
    {
    	String filterName = "Seller Filter";
    	
    	SelectBoxVal[] selectBoxes = {new SelectBoxVal(territoryType, ControlsMapping.SellerFilter.TerritoryType_listbox),
    			new SelectBoxVal(role, ControlsMapping.SellerFilter.Role_listbox),
    			new SelectBoxVal(sellerName, ControlsMapping.SellerFilter.SellerName_listbox)}; 
    	
		return applyFilter(filterName, selectBoxes, applyFilter);
    }
    
    public boolean applyProductFilter(String brandOfferingType, String subBrandSPL, String product, String coSE, String lessComplexProducts,
    		String smile, String sei, String bcrsRenewals, String dnso, String smallDeals, String top25Offering, String top30Offering)
    {
    	return applyProductFilter(brandOfferingType, subBrandSPL, product, coSE, lessComplexProducts,
        		smile, sei, bcrsRenewals, dnso, smallDeals, top25Offering, top30Offering, true);
    }
    
    public boolean applyProductFilter(String brandOfferingType, String subBrandSPL, String product, String coSE, String lessComplexProducts,
    		String smile, String sei, String bcrsRenewals, String dnso, String smallDeals, String top25Offering, String top30Offering, boolean applyFilter)
    {
    	String filterName = "Product Filter";
    	
    	SelectBoxVal[] selectBoxes = {new SelectBoxVal(brandOfferingType, ControlsMapping.ProductFilter.BrandOfferingType_listbox),
    			new SelectBoxVal(subBrandSPL, ControlsMapping.ProductFilter.SubBrandSPL_listbox),
    			new SelectBoxVal(product, ControlsMapping.ProductFilter.Product_listbox),
    			new SelectBoxVal(coSE, ControlsMapping.ProductFilter.Cose_listbox),
    			new SelectBoxVal(lessComplexProducts, ControlsMapping.ProductFilter.LessComplexProduct_listbox),
    			new SelectBoxVal(smile, ControlsMapping.ProductFilter.SMILE_listbox),
    			new SelectBoxVal(sei, ControlsMapping.ProductFilter.SEI_listbox),
    			new SelectBoxVal(bcrsRenewals, ControlsMapping.ProductFilter.BCRSRenewals_listbox),
    			new SelectBoxVal(dnso, ControlsMapping.ProductFilter.DNSO_listbox),
    			new SelectBoxVal(smallDeals, ControlsMapping.ProductFilter.SmallDeals_listbox),
    			new SelectBoxVal(top25Offering, ControlsMapping.ProductFilter.Top25OfferingITS_listbox),
    			new SelectBoxVal(top30Offering, ControlsMapping.ProductFilter.Top30Offering_listbox)}; 
    	
		return applyFilter(filterName, selectBoxes, applyFilter);
    }
    
    public boolean applyCustomerFilter(String sectors, String industry, String clientName, String clientID,
    		String customerName, String customerNumber, String coverageName, String coverageID)
    {
        return applyCustomerFilter(sectors, industry, clientName, clientID,
        		customerName, customerNumber, coverageName, coverageID, true);
    }
    
    public boolean applyCustomerFilter(String sectors, String industry, String clientName, String clientID,
    		String customerName, String customerNumber, String coverageName, String coverageID, boolean applyFilter)
    {
    	String filterName = "Customer Filter";
    	
    	SelectBoxVal[] selectBoxes = {new SelectBoxVal(sectors, ControlsMapping.CustomerFilter.Sector_listbox),
    			new SelectBoxVal(industry, ControlsMapping.CustomerFilter.Industry_listbox),
    			new SelectBoxVal(clientName, ControlsMapping.CustomerFilter.ClientName_listbox),
    			new SelectBoxVal(clientID, ControlsMapping.CustomerFilter.ClientID_listbox),
    			new SelectBoxVal(customerName, ControlsMapping.CustomerFilter.CustomerName_listbox),
    			new SelectBoxVal(customerNumber, ControlsMapping.CustomerFilter.CustomerNumber_listbox),
    			new SelectBoxVal(coverageName, ControlsMapping.CustomerFilter.CoverageName_listbox),
    			new SelectBoxVal(coverageID, ControlsMapping.CustomerFilter.CoverageID_listbox)}; 
    	
		return applyFilter(filterName, selectBoxes, applyFilter);
    }
    
    public boolean applyRevenueFilter(String opportunityRevenue, String totalOpportunityValue)
    {
    	return applyRevenueFilter(opportunityRevenue, totalOpportunityValue, true);
    }
    
    public boolean applyRevenueFilter(String opportunityRevenue, String totalOpportunityValue, boolean applyFilter)
    {
    	String filterName = "Revenue Filter";
    	
    	SelectBoxVal[] selectBoxes = {new SelectBoxVal(opportunityRevenue, ControlsMapping.RevenueFilter.OpportunityRevenue_listbox),
    			new SelectBoxVal(totalOpportunityValue, ControlsMapping.RevenueFilter.TotalOpportunityValue_listbox)}; 
    	
		return applyFilter(filterName, selectBoxes, applyFilter);
    }
    
    public boolean applyOpportunityFilter(String territory, String insideSalesInvolved, String salesStageGroup, String owningOrg,
    		String opptyRole, String opptySource, String pipelineAgeRevenue, String stuckPipeline, String duplicateOppty)
    {
    	return applyOpportunityFilter(territory, insideSalesInvolved, salesStageGroup, owningOrg,
        		opptyRole, opptySource, pipelineAgeRevenue, stuckPipeline, duplicateOppty, true);
    }
    
    public boolean applyOpportunityFilter(String territory, String insideSalesInvolved, String salesStageGroup, String owningOrg,
    		String opptyRole, String opptySource, String pipelineAgeRevenue, String stuckPipeline, String duplicateOppty, boolean applyFilter)
    {
    	String filterName = "Opportunity Filter";
    	
    	SelectBoxVal[] selectBoxes = {new SelectBoxVal(territory, ControlsMapping.OpportunityFilter.Territory_listbox),
    			new SelectBoxVal(insideSalesInvolved, ControlsMapping.OpportunityFilter.InsideSalesInvolved_listbox),	
    			new SelectBoxVal(salesStageGroup, ControlsMapping.OpportunityFilter.SalesStageGroup_listbox),	
    			new SelectBoxVal(owningOrg, ControlsMapping.OpportunityFilter.OwningOrg_listbox),
    			new SelectBoxVal(opptyRole, ControlsMapping.OpportunityFilter.OpptyRole_listbox),
    			new SelectBoxVal(opptySource, ControlsMapping.OpportunityFilter.OpptySource_listbox),
    			new SelectBoxVal(pipelineAgeRevenue, ControlsMapping.OpportunityFilter.PipelineAgeRange_listbox),
    			new SelectBoxVal(stuckPipeline, ControlsMapping.OpportunityFilter.StuckPipeline_listbox),
    			new SelectBoxVal(duplicateOppty, ControlsMapping.OpportunityFilter.DuplicateOppty_listbox)}; 
    	
		return applyFilter(filterName, selectBoxes, applyFilter);
    }
    
    //Will be finished when the Time Period filter is completed.
    private boolean applyTimePeriodDateFilter(TimePeriod timePeriod, String year, String option)
    {
    	switch(timePeriod)
    	{
	    	case Day:
	    	{
	    		
	    	}
	    	
	    	case Week:
	    	{
	    		
	    	}
	    	
	    	case Month:
	    	{
	    		
	    	}
	    	
	    	case Quarter:
	    	{
	    		
	    	}
    	}
    	
		return false;
    }
    
    public void testMain(Object[] args)
    {
    	applyGeographyFilter("Japan", "Canada", "Brazil", "Bulgaria");
    }
}

